package com.cloudptt.api.product.config.msg;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.PreferenceManager;

import com.cloudptt.api.product.log.Log;

public class MsgConfig implements OnSharedPreferenceChangeListener
{
	
	private static String THIS_FILE = "MsgConfig";
//	private static final String MSG_SP_FILE = "msg_config";
	
	private static final String MSG_URGENCY_NUM = "urgency_num";
	private static final String MSG_URGENCY_CONTENT = "urgency_content";

	private SharedPreferences sp = null;
	
	private String urgencyNum = "";
	private String urgencyContent = "";
	
	public MsgConfig(Context ctx)
	{
//		this.sp = ctx.getSharedPreferences(MSG_SP_FILE, Context.MODE_WORLD_WRITEABLE);
		this.sp = PreferenceManager.getDefaultSharedPreferences(ctx);
		
		this.urgencyNum = sp.getString(MSG_URGENCY_NUM,"18916010016");
		this.urgencyContent = sp.getString(MSG_URGENCY_CONTENT,"SOS");
		
		this.sp.registerOnSharedPreferenceChangeListener(this);
	}
//	
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) 
	{
		// TODO Auto-generated method stub
		if(null == key)
		{
			Log.e(THIS_FILE,"onSharedPreferenceChanged key = null");
			return;
		}
//		if(key.equals(SipConfigManager.PRIVATE_SPEAKER_SWITCH))
//		{
//			this.privateSpeakerOn = sharedPreferences.getBoolean(key, true);
//		}
		if(key.equals(MSG_URGENCY_NUM))
		{
			this.urgencyNum = sp.getString(MSG_URGENCY_NUM,"");
		}
		else if(key.equals(MSG_URGENCY_CONTENT))
		{
			this.urgencyContent = sp.getString(MSG_URGENCY_CONTENT,"");
		}
	}
	
	public void setUrgencyMsgInfo(String urgencyNum,String urgencyContent) {
		this.urgencyNum = urgencyNum;
		this.urgencyContent = urgencyContent;
		SharedPreferences.Editor editor = sp.edit();
		editor.putString(MSG_URGENCY_NUM, urgencyNum);
		editor.putString(MSG_URGENCY_CONTENT, urgencyContent);
		editor.commit();
	}
	public String getUrgencyNum() {
		return urgencyNum;
	}
	public String getUrgencyContent() {
		return urgencyContent;
	}
}
